package com.tajiang.business.setting.activity;

import android.content.Intent;
import android.os.Bundle;

import com.jungly.gridpasswordview.GridPasswordView;
import com.tajiang.business.R;
import com.tajiang.business.businesscount.wallet.ConfirmPsdActivity;
import com.tajiang.business.common.activity.BaseActivity;
import com.tajiang.business.common.http.BaseResponse;
import com.tajiang.business.common.http.HttpHandler;
import com.tajiang.business.common.http.HttpResponseListener;
import com.tajiang.business.common.utils.MD5Utils;
import com.tajiang.business.common.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 修改密码
 * Created by Administrator on 2016/5/10.
 */
public class ChangePsdActivity extends BaseActivity implements HttpResponseListener, GridPasswordView.OnPasswordChangedListener {

    private String oldPassword;

    @BindView(R.id.gpv_normal)
    GridPasswordView gpvNormal;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        gpvNormal.setOnPasswordChangedListener(this);
    }

    @Override
    protected void initTopBar() {
        setTitle(getResourcesString(R.string.msg_modify_password));
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_change_password);
    }

    @Override
    protected void initData() {

    }


    @Override
    public void onChanged(String psw) {

    }

    @Override
    public void onMaxLength(String psw) {
        oldPassword = psw;
        new HttpHandler(this).judgePwd(MD5Utils.StringMD5(oldPassword));
    }

    @Override
    public void onSuccess(BaseResponse response) {
        if (response.getData().equals("true")) {
            Intent intent = new Intent();
            intent.putExtra("mode", ConfirmPsdActivity.STATE_MODE_HAVE_PAY_PWD);
            intent.putExtra("oldPassword", oldPassword);
            intent.setClass(ChangePsdActivity.this, ResetPsdActivity.class);
            startActivity(intent);
            ChangePsdActivity.this.finish();
        } else {
            ToastUtils.showLong("原始密码错误！");
        }

    }

    @Override
    public void onFailed(BaseResponse response) {
        ToastUtils.showLong(response.getMoreInfo());
    }

    @Override
    public void onFinish() {

    }
}
